<template>
  <a-form @submit="handleSubmit" :form="form">
    <a-form-item
      label="任务名称："
      :labelCol="labelCol"
      :wrapperCol="wrapperCol"
    >
      <a-input v-decorator="['TaskName', {rules:[{required: true, message: '请输入任务名称'}]}]" />
    </a-form-item>
    <a-form-item
      label="时间范围："
      :labelCol="labelCol"
      :wrapperCol="wrapperCol"
    >
      <a-input-group>
        <a-row :gutter="26">
          <a-col :span="8">
            <a-input v-decorator="['StartTime', {rules:[{required: true, message: '请输入开始时间'}]}]" />
          </a-col>
          <a-col :span="8">
            <a-input v-decorator="['EndTime', {rules:[{required: true, message: '请输入结束时间'}]}]" />
          </a-col>
        </a-row>
      </a-input-group>
    </a-form-item>
    <a-form-item
      label="词句标题："
      :labelCol="labelCol"
      :wrapperCol="wrapperCol"
    >
      <a-input v-decorator="['TitleName', {rules:[{required: true, message: '请输入词句标题'}]}]" />
    </a-form-item>
    <a-button type="dashed" style="margin-left: 110px;">
      +添加
    </a-button>
  </a-form>
</template>

<script>
import pick from 'lodash.pick'

const fields = ['title', 'startAt', 'owner', 'description']

export default {
  name: 'NewDownloadForm',
  props: {
    record: {
      type: Object,
      default: null
    }
  },
  data () {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 13 }
      },
      form: this.$form.createForm(this)
    }
  },
  mounted () {
    this.record && this.form.setFieldsValue(pick(this.record, fields))
  },
  methods: {
    onOk () {
      console.log('监听了 modal ok 事件')
      return new Promise(resolve => {
        resolve(true)
      })
    },
    onCancel () {
      console.log('监听了 modal cancel 事件')
      return new Promise(resolve => {
        resolve(true)
      })
    },
    handleSubmit () {
      const { form: { validateFields } } = this
      this.visible = true
      validateFields((errors, values) => {
        if (!errors) {
          console.log('values', values)
        }
      })
    }
  }
}
</script>
